#!/usr/bin/env bash
# 系统更新 / 系统信息 / 安装并启用 cron
set -Eeuo pipefail

type log_info >/dev/null 2>&1 || { echo "[sysupdate] _common.sh 未加载"; exit 1; }

system_update() {
  ensure_root
  log_info "执行系统更新：apt update && apt upgrade -y && apt full-upgrade -y && apt autoremove -y"
  apt-get update
  DEBIAN_FRONTEND=noninteractive apt-get upgrade -y
  DEBIAN_FRONTEND=noninteractive apt-get full-upgrade -y
  apt-get autoremove -y
  log_info "系统已更新完成（包含 full-upgrade + autoremove）"
}

show_system_info() {
  echo "== 内核与架构 =="; uname -a
  echo
  echo "== CPU =="; lscpu 2>/dev/null | sed -n '1,12p' || true
  echo
  echo "== 内存 =="; free -h
  echo
  echo "== 磁盘 =="; df -hT
}

install_and_enable_cron() {
  ensure_root
  apt_quiet_update
  apt-get install -y cron
  systemctl enable cron
  systemctl start cron
  systemctl --no-pager -l status cron || true
  log_info "cron 已安装并启动（已设置开机自启）"
}
